<?php

namespace Mvc\Core;
/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-6-21
 * Time: 19:07
 * @description:注册器模式
 * @Author: yfl
 * @QQ 554665488
 */

class Register
{
    public static $instances = [];

    //获取
    public static function getInstance($key)
    {
        if (isset(self::$instances[$key])) {
            return self::$instances[$key];
        }
        return false;
    }

    //设置
    public static function setInstance($key, $value)
    {
        if (!isset(self::$instances[$key])) {
            self::$instances[$key] = $value;
        }else{
            throw  new \Exception("already $key has exist");
        }
    }

    //注销
    public static function _unset($key)
    {
        if(isset(self::$instances[$key])){
            unset(self::$instances[$key]);
        }
    }
}